package com.ruanhb.wsp.conifg;

import com.ruanhb.wsp.job.WeatherDataSyncJob;
import org.quartz.*;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Quartz Configuration
 * Created by r on 2018-8-29
 */
@Configuration
public class QuartzConfiguration {

    // jobDetail
    @Bean
    public JobDetail weatherDataSyncJobDetail() {
        return JobBuilder.newJob(WeatherDataSyncJob.class).withIdentity("weatherDataSyncJob","group_1")
                .storeDurably().build();
    }


    //Trigger
    @Bean
    public Trigger weatherDataSyncTrigger(){

        //每2秒执行一次
//        SimpleScheduleBuilder scheduleBuilder = SimpleScheduleBuilder.simpleSchedule()
//                .withIntervalInSeconds(1800).repeatForever();

        CronScheduleBuilder scheduleBuilder =
                CronScheduleBuilder.cronSchedule("0 */30 * * * ?"); //cron表达式


        return TriggerBuilder.newTrigger().forJob(weatherDataSyncJobDetail())
                .withIdentity("weatherDataSyncTrigger").withSchedule(scheduleBuilder).build();
    }

}
